//
//  HDQRCodeVC.m
//  HDWuDaDaoServiceCenter
//
//  Created by HDNiuKuiming on 2017/4/10.
//  Copyright © 2017年 HDNiuKuiming. All rights reserved.
//

#import "HDQRCodeVC.h"
#import "HDQRCodeInputVC.h"
#import "HDMapVC.h"

@interface HDQRCodeVC ()
{
    HDDeclare *declare;
    CGAffineTransform _captureSizeTransform;
}
@property (strong, nonatomic) IBOutlet UIView *scanRectView;
@property (weak, nonatomic) IBOutlet UIView *animateBgView;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet UILabel *tipLabel;

@property (nonatomic, strong) UIImageView * line;
@property (nonatomic, strong) NSTimer * timer;

@property (nonatomic, strong) NSString *museumID;

@end

@implementation HDQRCodeVC

#pragma mark
#pragma mark -------- Init Methods --------

- (void)viewDidLoad {
    [super viewDidLoad];
    declare = [HDDeclare sharedDeclare];
    
    [self.bgView bringSubviewToFront:self.scanRectView];
    [self.bgView bringSubviewToFront:self.scanRectView];
    [self.bgView bringSubviewToFront:_tipLabel];
    
    [self pushToQRCodeInputAcgion:nil];
}

- (IBAction)pushToQRCodeInputAcgion:(id)sender {
    [self performSegueWithIdentifier:@"QRCodePagePushToInputLine" sender:nil];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    upOrdown = NO;
    num =0;
    [self startScanAnimate];
}


-(void)animation1
{
//    CGFloat originY = 0;
//    CGFloat originX = _line.frame.origin.x;
//    CGFloat width = _line.frame.size.width;
//    
//    if (upOrdown == NO) {
//        num ++;
//        _line.frame = CGRectMake(originX, originY+2*num, width, 2);
//        if (2*num == _animateBgView.frame.size.height) {
//            upOrdown = YES;
//        }
//    }
//    else {
//        num --;
//        _line.frame = CGRectMake(originX, originY+2*num, width, 2);
//        if (num == 0) {
//            upOrdown = NO;
//        }
//    }
}

- (void)startScanAnimate
{
//    dispatch_async(dispatch_get_main_queue(), ^{
//        _line = [[UIImageView alloc] initWithFrame:CGRectMake(20, 10, _animateBgView.frame.size.width-40, 2)];
//        _line.contentMode = UIViewContentModeScaleToFill;
//        _line.image = [UIImage imageNamed:@"QRCode_line"];
//        [self.animateBgView addSubview:_line];
//        
//        _timer = [NSTimer scheduledTimerWithTimeInterval:.02 target:self selector:@selector(animation1) userInfo:nil repeats:YES];
//    });
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"QRPagePushToMapLine"]) {
        HDMapVC *VC = segue.destinationViewController;
        VC.museumID = _museumID;
    }
}

#pragma mark
#pragma mark -------- Dealloc Methods --------

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)backActin:(id)sender {
    [self cameraClean];
    [super back];
}

- (void)cameraClean
{
    [_timer invalidate];
    self.timer = nil;
    self.line = nil;
}

- (void)dealloc
{
    [self cameraClean];
}

@end
